package org.linlinjava.litemall.db.service;

import org.linlinjava.litemall.db.dao.AgedmallLeaseGoodsReturnRecordMapper;
import org.linlinjava.litemall.db.dao.app.AppLeaseGoodsReturnRecordMapper;
import org.linlinjava.litemall.db.domain.AgedmallLeaseGoodsReturnRecord;
import org.linlinjava.litemall.db.domain.AgedmallLeaseGoodsReturnRecordExample;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

@Service
public class AgedmallLeaseGoodsReturnRecordService {
    @Resource
    private AgedmallLeaseGoodsReturnRecordMapper agedmallLeaseGoodsReturnRecordMapper;
    @Resource
    private AppLeaseGoodsReturnRecordMapper appLeaseGoodsReturnRecordMapper;

    public void add(AgedmallLeaseGoodsReturnRecord agedmallLeaseGoodsReturnRecord) {
        agedmallLeaseGoodsReturnRecord.setAddTime(LocalDateTime.now());
        agedmallLeaseGoodsReturnRecord.setUpdateTime(LocalDateTime.now());
        agedmallLeaseGoodsReturnRecordMapper.insertSelective(agedmallLeaseGoodsReturnRecord);
    }

    public void delete(AgedmallLeaseGoodsReturnRecord agedmallLeaseGoodsReturnRecord) {
        agedmallLeaseGoodsReturnRecord.setDeleted(true);
        agedmallLeaseGoodsReturnRecordMapper.updateByPrimaryKey(agedmallLeaseGoodsReturnRecord);
    }

    public void update(AgedmallLeaseGoodsReturnRecord agedmallLeaseGoodsReturnRecord) {
        agedmallLeaseGoodsReturnRecord.setUpdateTime(LocalDateTime.now());
        agedmallLeaseGoodsReturnRecordMapper.updateByPrimaryKey(agedmallLeaseGoodsReturnRecord);
    }

    public AgedmallLeaseGoodsReturnRecord findByOrderIdAndSubOrderId(String bigOrderId, String subOrderId) {
        return appLeaseGoodsReturnRecordMapper.findByOrderIdAndSubOrderId(bigOrderId, subOrderId);
    }
    public List<AgedmallLeaseGoodsReturnRecord> findByOrderIds(List<Long> bigOrderIdList) {
        if(bigOrderIdList.size() == 0) {
            return new ArrayList<>();
        }
        List<String> bigOrderIdStrList = new ArrayList<>();
        bigOrderIdList.stream().forEach(id->{
            bigOrderIdStrList.add(id.toString());
        });
        AgedmallLeaseGoodsReturnRecordExample example = new AgedmallLeaseGoodsReturnRecordExample();
        example.createCriteria().andBigOrderIdIn(bigOrderIdStrList).andDeletedEqualTo(false);
        return agedmallLeaseGoodsReturnRecordMapper.selectByExample(example);
    }
}
